package com.example.android;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    //定义按钮和标题
    private Button Btn01;
    private Button Btn02;
    private Button Btn03;
    private Button Btn04;
    private TextView Title;

//    private AlertDialog dialog02;
//    private AlertDialog.Builder builder02;
    private AlertDialog dialog = null;
    private  AlertDialog.Builder builder = null;




    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        //设置全屏
        //getWindow().setFlags(Window.LayoutParam.FLAG_FULLSCREEN);
        //加入布局
        setContentView(R.layout.buju);
        Title = (TextView)findViewById(R.id.MainTitle);
        Btn01 = (Button)findViewById(R.id.Btn01);
        Btn01.setOnClickListener(this);
        Btn02 = (Button)findViewById(R.id.Btn02);
        //设置点击监听
        Btn02.setOnClickListener(this);
        Btn03 = (Button)findViewById(R.id.Btn03);
        Btn03.setOnClickListener(this);
        Btn04 = (Button)findViewById(R.id.Btn04);
        Btn04.setOnClickListener(this);
        Runnable mRunnable = new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this, "欢迎来到界面", Toast.LENGTH_SHORT).show();
            }
        };
        mRunnable.run();
        Log.v("MainActivity","toast销毁");
    }
//    public static void startActivity(Context context){
//        builder02 = new AlertDialog.Builder(this);
//        dialog02 = builder.setIcon(R.drawable.ic_launcher_foreground) //设置图标
//                .setTitle("提示")//设置标题
//                .setMessage("欢迎来到主界面")//设置弹窗文本内容
//                //设置确定按钮
//                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        Toast.makeText(MainActivity.this, "您点击了确认按钮，进入主界面", Toast.LENGTH_SHORT).show();
//                    }}).create();
//
//        dialog02.show();
//
//    }

    @Override
    public void onClick(View view) {
        final int flag[] = new int[]{0};
        switch (view.getId()) {
            case R.id.Btn01:
                Btn01.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        if(flag[0] == 0){
                            Btn01.setBackgroundColor(Color.DKGRAY);
                            flag[0] = 1;
                        }
                        else if(flag[0] ==1){
                            Btn01.setBackgroundColor(Color.GREEN);
                            flag[0] = 2;
                        }
                        else{
                            Btn01.setBackgroundColor(Color.RED);
                            flag[0] = 0;
                        }
                    }
                });
                break;

            case R.id.Btn02:
                Intent PictureTest = new Intent(MainActivity.this, Picture.class);
                startActivity(PictureTest);
                break;

            case R.id.Btn03:
                Intent Newpage = new Intent(MainActivity.this,NewPage.class);
                startActivity(Newpage);
                break;

            case R.id.Btn04:

                builder = new AlertDialog.Builder(this);
                dialog = builder.setIcon(R.drawable.ic_launcher_foreground) //设置图标
                        .setTitle("这是一个简单的Android弹窗")//设置标题
                        .setMessage("欢迎来到弹窗界面")//设置弹窗文本内容
                        //设置确定按钮
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this, "您点击了确认按钮，返回主界面", Toast.LENGTH_SHORT).show();
                            }
                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this, "您点击了取消按钮，返回主界面", Toast.LENGTH_SHORT).show();
                            }
                        }).create();
                dialog.show();
                break;

        }
    }
}
